package com.ruoyi.bussine.common.enums.order;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author zhengyz
 * @date 2025/3/13
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {

    /**
     * 门店：
     * 待出库：WAIT_OUT、已出库:OUT_STOCK、配送中:SENDING、已完成:COMPLETED
     *
     * 消费：
     * 待付款：WAIT_PAY、支付失败：PAY_FAILED待配送：WAIT_THIRD、配送中:THIRD_SENDING、已完成:COMPLETED
     *
     * 回收：
     * 待回收：WAIT_RECYCLED、待回库:WAIT_RETURN、已完成:COMPLETED
     */
    STORE_WAIT_OUT("WAIT_OUT", OrderTypeEnum.STORE, "待出库"),
    STORE_OUT_STOCK("OUT_STOCK", OrderTypeEnum.STORE, "已出库"),
    STORE_SENDING("SENDING", OrderTypeEnum.STORE, "配送中"),

    CONSUMER_WAIT_PAY("WAIT_PAY", OrderTypeEnum.CONSUMER, "待付款"),
//    CONSUMER_PAY_FAILED("PAY_FAILED", OrderTypeEnum.CONSUMER, "支付失败"),
    CONSUMER_WAIT_THIRD("WAIT_THIRD", OrderTypeEnum.CONSUMER, "待配送"),
    CONSUMER_THIRD_SENDING("THIRD_SENDING", OrderTypeEnum.CONSUMER, "配送中"),
    CONSUMER_CLOSE("CLOSE", OrderTypeEnum.CONSUMER, "订单关闭"),

    RECYCLE_WAIT_RECYCLED("WAIT_RECYCLED", OrderTypeEnum.RECYCLE, "待回收"),
    RECYCLE_WAIT_RETURN("WAIT_RETURN", OrderTypeEnum.RECYCLE, "待回库"),

    /**
     *
     * 进货订单：已提交（待出库），待取货（已出库），已发货（配送中），已完成
     * 待出库、已出库、配送中、已完成
     *//*
    SUBMITTED("SUBMITTED", OrderTypeEnum.STORE, "已提交"),
    WAIT_SEND("WAIT_SEND", OrderTypeEnum.STORE, "待取货"),
    SENDING("SENDING", OrderTypeEnum.STORE, "已发货"),

    *//**
     * 消费者订单：待付款，待发货（支付完成），已发货，已完成
     * 待付款、待配送、配送中、已完成
     *//*
    WAIT_PAY("WAIT_PAY", OrderTypeEnum.CONSUMER, "待付款"),
    WAIT_SEND_CONSUMER("WAIT_SEND", OrderTypeEnum.CONSUMER, "待发货"),
    SENDING_CONSUMER("SENDING", OrderTypeEnum.CONSUMER, "已发货"),

    *//**
     * 回收订单：已提交（待回收），已取货（待回库），已入库（已回库，已完成）
     * 待回收、待回库、已完成
     *//*
    SUBMITTED_RECYCLE("SUBMITTED", OrderTypeEnum.RECYCLE, "已提交"),
    RECYCLED("WAIT_RECYCLED", OrderTypeEnum.RECYCLE, "待回收"),*/

    CLOSE("CLOSE", OrderTypeEnum.CONSUMER, "订单关闭"),
    COMPLETED("COMPLETED", null, "已完成");


    private String value;
    private OrderTypeEnum orderType;
    private String desc;

    // 验证订单类型的操作是否合法
    public static boolean isValid(String value, OrderTypeEnum orderType) {
        // 已完成是公共的，所以可以忽略类型
        if (COMPLETED.getValue().equals(value)) {
            return true;
        }
        for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
            if (orderStatusEnum.getValue().equals(value) && orderStatusEnum.getOrderType().equals(orderType)) {
                return true;
            }
        }
        return false;
    }

}
